import { MenuEnum } from "@/enum";
import { getUUID } from "@/utils";
import type LogicFlow from "@logicflow/core"
import type { ApprovalNodeType, ConditionNodeType, CopyNodeType } from "./types";

export const useCreateNodes = ()=>{
    const createStartNode = (lf:LogicFlow,x:number,y:number)=>{
        const node = {
            id:'node' + getUUID(),
            type: 'customGlobal',
            x:x,
            y:y,
            properties:{ //动态设置
                name:'开始节点',
                prop:MenuEnum.START,
                width:80,
                height:50
            }
        }
        lf.addNode(node);
    }
    const createEndNode = (lf:LogicFlow,x:number,y:number)=>{
        const node = {
            id:'node' + getUUID(),
            type: 'customGlobal',
            x:x,
            y:y,
            properties:{ //动态设置
                name:'结束节点',
                prop:MenuEnum.END,
                width:80,
                height:50
            }
        }
        lf.addNode(node);
    }
    const createApprovalNode = (lf:LogicFlow,x:number,y:number)=>{
        const node:ApprovalNodeType = {
            id:'node' + getUUID(),
            type: 'customNode',
            x:x,
            y:y,
            properties:{ //动态设置
                name:'审批节点',
                prop:MenuEnum.APPROVAL,
                width:210,
                height:80,
                approvalType:1,
                assignable:true,
                signable:true,
                desc:"",
                assigneeType:1,
                layer:-1,
                assignees:[]

            }
        }
        lf.addNode(node);
    }
    const createConditionNode = (lf:LogicFlow,x:number,y:number)=>{
        const node:ConditionNodeType = {
            id:'node' + getUUID(),
            type: 'customNode',
            x:x,
            y:y,
            properties:{ //动态设置
                name:'条件节点',
                prop:MenuEnum.CONDITION,
                width:210,
                height:80,
                conditions:[]
            }
        }
        lf.addNode(node);
    }

    const createCopyNode = (lf:LogicFlow,x:number,y:number)=>{
        const node:CopyNodeType = {
            id:'node' + getUUID(),
            type: 'customNode',
            x:x,
            y:y,
            properties:{ //动态设置
                name:'抄送节点',
                prop:MenuEnum.COPY,
                width:210,
                height:80
            }
        }
        lf.addNode(node);
    }
    return {
        createStartNode,
        createEndNode,
        createApprovalNode,
        createConditionNode,
        createCopyNode
    }
}